#!/bin/sh

set -eu

build() {
    mkdir -p "build_$1"
    cd "build_$1"
    cmake \
        -D CMAKE_BUILD_TYPE=Release \
        -D CMAKE_OSX_DEPLOYMENT_TARGET="10.15" \
        -D CMAKE_OSX_ARCHITECTURES="$1" \
        -D CMAKE_SYSTEM_PROCESSOR="$1" \
        -D DEPS=DOWNLOAD \
        -D ENABLE_TESTING=OFF \
        ..
    cmake --build .
    cd ..
}

FILES=""
set -- x86_64 arm64

for i in "$@"; do
    echo "Building $i"
    build "$i"
    FILES="${FILES} build_$i/ccache"
done

mkdir -p build_universal
lipo -create $FILES -output build_universal/ccache
lipo -info build_universal/ccache
